| Conditions | 14 |
| Paths | 2048 |
| Total Lines | 85 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like AbstractAjaxRemote.ajaxRequest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | |||
| 131 | let |
||
| 132 | action = ''; |
||
| 133 | |||
| 134 | params = params || {}; |
||
| 135 | action = params.Action || ''; |
||
| 136 | |||
| 137 | if (action && 0 < abortActions.length) |
||
| 138 | { |
||
| 139 | _.each(abortActions, (actionToAbort) => { |
||
| 140 | if (this.oRequests[actionToAbort]) |
||
| 141 | { |
||
| 142 | this.oRequests[actionToAbort].__aborted = true; |
||
| 143 | if (this.oRequests[actionToAbort].abort) |
||
| 144 | { |
||
| 145 | this.oRequests[actionToAbort].abort(); |
||
| 146 | } |
||
| 147 | this.oRequests[actionToAbort] = null; |
||
| 148 | } |
||
| 149 | }); |
||
| 150 | } |
||
| 151 | |||
| 152 | if (isPost) |
||
| 153 | { |
||
| 154 | params.XToken = Settings.appSettingsGet('token'); |
||
| 155 | } |
||
| 156 | |||
| 157 | const oDefAjax = $.ajax({ |
||
| 158 | type: isPost ? 'POST' : 'GET', |
||
| 159 | url: ajax(sGetAdd), |
||
| 160 | async: true, |
||
| 161 | dataType: 'json', |
||
| 162 | data: isPost ? params : {}, |
||
| 163 | headers: headers, |
||
| 164 | timeout: iTimeOut, |
||
| 165 | global: true |
||
| 166 | }); |
||
| 167 | |||
| 168 | oDefAjax.always((oData, sType) => { |
||
| 169 | |||
| 170 | let cached = false; |
||
| 171 | if (oData && oData.Time) |
||
| 172 | { |
||
| 173 | cached = pInt(oData.Time) > (new window.Date()).getTime() - start; |
||
| 174 | } |
||
| 175 | |||
| 176 | if (action && this.oRequests[action]) |
||
| 177 | { |
||
| 178 | if (this.oRequests[action].__aborted) |
||
| 179 | { |
||
| 180 | sType = 'abort'; |
||
| 181 | } |
||
| 182 | |||
| 183 | this.oRequests[action] = null; |
||
| 184 | } |
||
| 185 | |||
| 186 | this.defaultResponse(fResultCallback, action, sType, oData, cached, params); |
||
| 187 | }); |
||
| 188 | |||
| 189 | if (action && 0 < abortActions.length && -1 < inArray(action, abortActions)) |
||
| 190 | { |
||
| 191 | if (this.oRequests[action]) |
||
| 192 | { |
||
| 193 | this.oRequests[action].__aborted = true; |
||
| 194 | if (this.oRequests[action].abort) |
||
| 195 | { |
||
| 196 | this.oRequests[action].abort(); |
||
| 197 | } |
||
| 198 | this.oRequests[action] = null; |
||
| 199 | } |
||
| 200 | |||
| 201 | this.oRequests[action] = oDefAjax; |
||
| 202 | } |
||
| 203 | |||
| 204 | return oDefAjax; |
||
| 205 | } |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @param {?Function} fCallback |
||
| 209 | * @param {string} sAction |
||
| 210 | * @param {Object=} oParameters |
||
| 211 | * @param {?number=} iTimeout |
||
| 212 | * @param {string=} sGetAdd = '' |
||
| 213 | * @param {Array=} aAbortActions = [] |
||
| 214 | */ |
||
| 215 | defaultRequest(fCallback, sAction, oParameters, iTimeout, sGetAdd, aAbortActions) { |
||
| 216 | oParameters = oParameters || {}; |
||
| 287 |